package com.sirun.cn.fca.module.main.home.temp.status;

import android.graphics.drawable.Drawable;

import com.sirun.cn.fca.R;
import com.tencent.cloud.iov.util.ObjectUtils;
import com.tencent.cloud.iov.util.ResourcesUtils;

/**
 * @author showxiao
 * @date 2018/8/11
 */
public class HomeCarStatusItem implements IHomeCarStatusItem {

    private final Drawable mCarStatusIcon;
    private final CharSequence mCarStatusText;

    private final float mMileageLeftRatio;
    private final CharSequence mMileageNumberImageString;

    public HomeCarStatusItem(int exceptionCount, int mileageLeft, int maxMileage,
                             CharSequence mileageNumberImageString) {
        if (exceptionCount <= 0) {
            mCarStatusIcon = ResourcesUtils.getDrawable(R.drawable.ic_home_car_status);
            mCarStatusText = ResourcesUtils.getString(R.string.home_car_status_normal);
        } else {
            mCarStatusIcon = ResourcesUtils.getDrawable(R.drawable.ic_home_car_status);
            mCarStatusText = ResourcesUtils.getString(R.string.home_car_status_normal);
        }

        mMileageLeftRatio = (float) mileageLeft / maxMileage;
//        mMileageNumberImageString = MileageNumberParser.parseNumberToImageString(mileageLeft);
        mMileageNumberImageString = mileageNumberImageString;
    }

    @Override
    public Drawable getCarStatusIcon() {
        return mCarStatusIcon;
    }

    @Override
    public CharSequence getCarStatusText() {
        return mCarStatusText;
    }

    @Override
    public CharSequence getMileageImageString() {
        return mMileageNumberImageString;
    }


    @Override
    public float getMileageLeftRatio() {
        return mMileageLeftRatio;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        HomeCarStatusItem that = (HomeCarStatusItem) o;
        return
                Float.compare(that.mMileageLeftRatio, mMileageLeftRatio) == 0 &&
                        ObjectUtils.equals(mCarStatusIcon, that.mCarStatusIcon) &&
                        ObjectUtils.equals(mCarStatusText, that.mCarStatusText) &&
                        ObjectUtils.equals(mMileageNumberImageString, that.mMileageNumberImageString);
    }

    @Override
    public int hashCode() {
        return ObjectUtils.hash(mCarStatusIcon, mCarStatusText,
                mMileageLeftRatio, mMileageNumberImageString);
    }
}
